package com.chuji.crmcj.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuji.crmcj.R;
import com.chuji.crmcj.bean.OrderListInfo;
import com.chuji.crmcj.utils.NumberUtils;

import java.util.List;

/**
 * Created by w.pitt on 2016/1/15.
 */
public class OrderAdapter extends BaseAdapter {
    private Context mContext;
    private SaleViewHolder holder;
    private List<OrderListInfo.ApiParamObjEntity> orderListInfo;

    public OrderAdapter(Context context, List<OrderListInfo.ApiParamObjEntity> mOrderList) {
        this.mContext = context;
        this.orderListInfo = mOrderList;
    }

    @Override
    public int getCount() {
        return orderListInfo.isEmpty() ? 0 : orderListInfo.size();
    }

    @Override
    public Object getItem(int i) {
        return orderListInfo.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = view.inflate(mContext, R.layout.item_coustomer_list, null);
            holder = new SaleViewHolder();
            holder.mIvCusLevel = (ImageView) view.findViewById(R.id.iv_level);
            holder.mIvCusLevel.setVisibility(View.GONE);
            holder.mTvWantCar = (TextView) view.findViewById(R.id.tv_want_car);
//            holder.mTvSalerName = (TextView) view.findViewById(R.id.tv_sale_name);
            holder.mTvLeastTime = (TextView) view.findViewById(R.id.tv_least_time);
            holder.mTvCusName = (TextView) view.findViewById(R.id.tv_name);
            holder.mTvCusNum = (TextView) view.findViewById(R.id.tv_number);
            view.setTag(holder);
        } else {
            holder = (SaleViewHolder) view.getTag();
        }
//            holder.mTvSalerName.setVisibility(View.VISIBLE);
        holder.mTvCusName.setText(orderListInfo.get(i).getName());
        String tel = orderListInfo.get(i).getTel();
        if (tel.length() == 11) {
            holder.mTvCusNum.setText(NumberUtils.parsePhoneNumber(tel));
        } else {
            holder.mTvCusNum.setText(orderListInfo.get(i).getTel());
        }

        holder.mTvLeastTime.setText(orderListInfo.get(i).getCreateTime());
        holder.mTvWantCar.setText(orderListInfo.get(i).getCarModel());
        return view;
    }

    public List<OrderListInfo.ApiParamObjEntity> getList() {
        return orderListInfo;
    }

    static class SaleViewHolder {
        private TextView mTvWantCar;
        private TextView mTvSalerName;
        private TextView mTvCusName;
        private TextView mTvCusNum;
        private TextView mTvLeastTime;
        private ImageView mIvCusLevel;
    }
}
